<!DOCTYPE html>
<html lang="en">
<head>
    <title>一般缴款书手工票</title>
    <#include "../inc/header.ftl"/>
    <link rel="stylesheet" href="${prefix}/assets/custom/css/main.css" />
</head>

<body class="no-skin">

<div class="main-container ace-save-state" id="main-container">

    <div class="main-content">
        <div class="main-content-inner">

            <div class="page-content">
                <table width="800" border="0" align="center" cellpadding="0" cellspacing="0" class="r_tablebr">
                    <tr>
                        <td class="r_nr">
                            <table width="99%" border="0" cellspacing="0" cellpadding="0">
                                <tr>
                                    <td class="r_title">河北省非税收入一般缴款书</td>
                                </tr>
                            </table>
                            <form name="ChargeBillHandForm" id="ChargeBillHandForm" action="ChargeBillHandData" method="post">
                                <table width="99%" border="0" cellpadding="0" cellspacing="0" class="r_zsdwbm">
                                    <input name="ischeck" type="hidden" id="ischeck" value=""/>
                                    <input name="bankid" type="hidden" id="bankid" value=""/>
                                    <input name="ishave1" type="hidden" id="ishave1" value="false"/>
                                    <input name="ishave2" type="hidden" id="ishave2" value="false"/>
                                    <input name="ishave3" type="hidden" id="ishave3" value="false"/>
                                    <input name="eticketnum" type="hidden" id="eticketnum" value=""/>
                                    <input name="vertifycode" type="hidden" id="vertifycode" value=""/>
                                    <input name="isscale" type="hidden" id="isscale" value=""/>
                                    <tr>
                                        <td>行政区划编码：
                                            <input name="cantoncode" type="text" id="cantoncode"/>
                                        </td>
                                        <td align="right"><b>N0</b>
                                            <input name="billnum" type="text" id="billnum" value="" class="r_input2" style="width:100px;" /></td>
                                        <td>交易流水号<input type="text" id="bankaffirm" name="bankaffirm" value="" class="r_input2" style="width:90px;"></td>
                                    </tr>
                                    <tr>
                                        <td>执收单位编码：
                                            <input name="unitcode" type="text" id="unitcode" value="" class="" />
                                        </td>
                                        <td align="center" class="r_zsdwbmwz">&nbsp;</td>
                                        <td align="right" class="r_zsdwbmwz">&nbsp;</td>
                                    </tr>
                                    <tr>
                                        <td width="40%">执收单位名称：
                                            <input name="unitname" type="text" readonly="readonly" id="unitname" style="width:230px" value="" class="r_input3" /></td>
                                        <td width="20%" align="center" class="r_zsdwbmwz">开票日期：<input id="filldate" name="filldate" class="easyui-datebox" style="width:100px"></td>
                                        <td width="20%" align="right" class="r_zsdwbmwz"><input type="button" name="button6" id="button6"  class="r_button" value="校验票号" onclick="queryChargeBillHandData()"/></td>
                                    </tr>
                                </table>
                                <table width="99%" border="1" cellpadding="0" cellspacing="1" class="r_jcxx2">
                                    <tr>
                                        <td width="15%" align="right">付款人全称</td>
                                        <td width="35%"><input name="payer" type="text" id="payer" class="" style="width:95%;background:#ffffff" value="" /></td>
                                        <td width="15%" align="right">收款人全称</td>
                                        <td width="35%"><input name="payee" readonly="readonly" type="text" id="payee" style="width:95%" value="" /></td>
                                    </tr>
                                    <tr>
                                        <td align="right">付款人账号</td>
                                        <td><input type="text" name="payeraccount" id="payeraccount" value="" class="" style="width:95%;background:#ffffff" /></td>
                                        <td width="15%" align="right">收款人账号</td>
                                        <td><input name="payeeaccount" type="text" readonly="readonly" id="payeeaccount" style="width:95%" value="" /></td>
                                    </tr>
                                    <tr>
                                        <td align="right">付款人开户银行</td>
                                        <td><input type="text" name="payerbank" id="payerbank" value="" class="" style="width:95%;background:#ffffff" /></td>
                                        <td width="15%" align="right">收款人开户银行</td>
                                        <td><label for="select2"></label>
                                            <select name="payeebank" id="payeebank" style="width:95%">
                                            </select></td>
                                    </tr>
                                </table>
                                <table width="99%" border="1" cellpadding="0" cellspacing="1" class="r_jcxx3" id="tab">
                                    <tr>
                                        <td width="10%" align="center">编码</td>
                                        <td width="5%" align="center">&nbsp;</td>
                                        <td width="40%" align="center">收入项目</td>
                                        <td width="10%" align="center">数量</td>
                                        <td width="20%" align="center">收缴标准</td>
                                        <td width="10%" align="center">金额</td>
                                    </tr>
                                    <tr id="tab-tr1">
                                        <td align="center"><input name="itemcode1"  id="itemcode1" style="border: 0;"/></td>
                                        <td><input type="button" name="btnUnitVsItem1" id="btnUnitVsItem1" hidden class="r_button2" value="X" onclick="openfwfcz3(1)"/></td>
                                        <td><input name="itemname1" readonly="true" id="itemname1" readonly="true" style="border: 0;"/></td>
                                        <td width="15%" align="center"><input name="sl1" hidden id="sl1" hidden style="border: 1;"/>
                                        </td>
                                        <td align="center"><input name="upperlimit1" readonly="true" id="upperlimit1" width="10px" hidden value="0.00~~0.00" style="border: 0;"/></td>
                                        <td align="center"><input name="originfund1" id="originfund1" value="0" onblur="fundadd()" hidden style="border: 1;"/>
                                        </td>
                                    </tr>
                                    <tr id="tab-tr2">
                                        <td align="right"><input name="itemcode2" id="itemcode2" style="border: 0;" /></td>
                                        <td> <input type="button" name="btnUnitVsItem2" id="btnUnitVsItem2" hidden class="r_button2" value="X" onclick="openfwfcz3(2)"/></td>
                                        <td><input name="itemname2" readonly="true" id="itemname2" readonly="true" style="border: 0;"/></td>
                                        <td width="15%" align="center"><input name="sl2" hidden id="sl2" style="border: 1;"/></td>
                                        <td align="center"><input name="upperlimit2" readonly="true" id="upperlimit2" width="10px" hidden value="0.00~~0.00" style="border: 0;"/>
                                        </td>
                                        <td align="center"><input name="originfund2" hidden id="originfund2" value="0" onblur="fundadd()" style="border: 1;"/></td>
                                    </tr>
                                    <tr id="tab-tr3">
                                        <td align="right"><input name="itemcode3"  id="itemcode3" style="border: 0;"/></td>
                                        <td><input type="button" name="btnUnitVsItem3" id="btnUnitVsItem3" hidden class="r_button2" value="X" onclick="openfwfcz3(3)"/></td>
                                        <td><input name="itemname3" id="itemname3" readonly="true" style="border: 0;"/></td>
                                        <td align="center"><input name="sl3" hidden  id="sl3" style="border: 1;"/></td>
                                        <td align="center">
                                            <input name="upperlimit3" readonly="true" id="upperlimit3" width="10px" hidden value="0.00~~0.00" style="border: 0;"/>
                                        </td>
                                        <td align="center"><input name="originfund3" hidden id="originfund3" value="0" onblur="fundadd()" style="border: 1;"/></td>
                                    </tr>
                                </table>
                                <table width="99%" border="0" cellpadding="0" cellspacing="0" class="r_zsdwbm">
                                    <tr>
                                        <td align="left">付款方式：
                                            <input name="paywaycode" type="text" id="paywaycode" class="r_input2" style="width:80px"/>
                                        </td>
                                        <td align="right">金额（大写）：
                                            <input name="bigoriginfund" type="text" id="bigoriginfund" class="r_input" readonly="readonly" style="width:250px" value="" />
                                            （小写）：
                                            <input name="originfund" type="text" id="originfund" class="r_input" readonly="readonly" style="width:80px" value="" /></td>
                                    </tr>
                                </table>
                            </form>
                            <table width="99%" border="0" cellspacing="0" cellpadding="0">
                                <tr>
                                    <td height="40" align="right">
                                        <input type="button" name="paybutton" id="paybutton"  class="r_button" onclick="pay()" value="收款" />
                                        <input type="button" name="button3" id="button3"  class="r_button" value="关闭" />
                                    </td>
                                </tr>
                            </table></td>
                    </tr>
                </table>
            </div><!-- /.page-content -->

        </div>
    </div><!-- /.main-content -->
</div><!-- /.main-container -->

<!-- basic scripts -->
<#include "../inc/basicjs.ftl"/>
<script src="${prefix}/assets/custom/js/commonview.js"></script>
<!-- inline scripts related to this page -->
<script type="text/javascript">
    $(function(){
        var curr_time = new Date();
        var str = curr_time.getFullYear()+"-";
        str += curr_time.getMonth()+1+"-";
        str += curr_time.getDate()+"-";
        $('#filldate').datebox('setValue',str);
    });
    //缴款方式下拉框
    $('#paywaycode').combobox({
        url:prefix + '/base/basedata/findPayWay',
        valueField:'paywayid',
        textField:'paywayname',
        panelHeight:'auto',
        onLoadSuccess:function(){
            var data = $('#paywaycode').combobox('getData');//获取所有下拉框数据
            if (data.length > 0) {
                //如果有数据的话默认选中第一条数据
                $('#paywaycode').combobox('select',data[0].paywayid);
            }
        }
    });
   function fundadd(){
       var originfund1 = $('#originfund1').val();
       var originfund2 = $('#originfund2').val();
       var originfund3 = $('#originfund3').val();
      var a = parseFloat((originfund1==null||originfund1==''?0:originfund1))+parseFloat((originfund2==null||originfund1==''?0:originfund2))+parseFloat((originfund3==null||originfund1==''?0:originfund3));
       $('#originfund').val(a);
       $('#bigoriginfund').val(upDigit(a));
   }


    //---区划三级下拉框
    $('#cantoncode').combotree({
        url:prefix+'/base/basedata/findUserCantonMap',
        required: true,
        width: 200
    });


    $('#cantoncode').combo({
        onChange: function(){
            var t = $('#cantoncode').combotree('tree');	// get the tree object
            var n = t.tree('getSelected');
            $('#unitcode').combogrid({
                panelWidth:520,
                panelMaxHeight:150,
                idField:'unitid',
                textField:'unitcode',
                url:prefix+'/base/basedata/findUnitTwo',
                queryParams: {cantonid:n.id},
                columns:[[
                    {field:'unitid',title:'ID',width:80},
                    {field:'unitcode',title:'单位编码',width:160},
                    {field:'unitname',title:'单位名称',width:260}
                ]],
            });
        }
    })

    $('#unitcode').combogrid({
        onChange: function(){
            var g = $('#unitcode').combogrid('grid');	// get datagrid object
            var r = g.datagrid('getSelected');	// get the selected row
            $('#unitname').val(r.unitname);
        }
    })
    function openfwfcz3(opt) {
        if(opt==1){
            $('#itemcode1').combogrid('clear');
            $('#itemname1').val('');
            $('#sl1').hide();
            $('#originfund1').hide();
            $('#upperlimit1').hide();
            $('#btnUnitVsItem1').hide();
        }
        if(opt==2){
            $('#itemcode2').combogrid('clear');
            $('#itemname2').val('');
            $('#sl2').hide();
            $('#originfund2').hide();
            $('#upperlimit2').hide();
            $('#btnUnitVsItem2').hide();
        }
        if(opt==3){
            $('#itemcode3').combogrid('clear');
            $('#itemname3').val('');
            $('#sl3').hide();
            $('#originfund3').hide();
            $('#upperlimit3').hide();
            $('#btnUnitVsItem3').hide();
        }
        $("#ishave"+opt).val("false");
        fundadd();
    }
    function evaluay() {
        var ischeck = $("#ischeck").val();
        if(ischeck!="1"){
            $.messager.alert('提示','校验票号未通过！', 'info');
            return;
        }
        var g = $('#unitcode').combogrid('grid');	// get datagrid object
        var r = g.datagrid('getSelected');	// get the selected row
        $('#itemcode1,#itemcode2,#itemcode3').combogrid({
            panelWidth:240,
            panelMaxHeight: 150,
            idField:'itemcode',
            textField:'itemcode',
            url:prefix+'/base/basedata/findUnitVsItemView',
            queryParams: {unitid:r.unitid},
            columns:[[
                {field:'itemcode',title:'编号',width:80},
                {field:'itemname',title:'名称',width:160}
            ]],
        });
    }

    $('#itemcode1').combogrid({
        onChange: function(){
            var r = $('#itemcode1').combogrid('grid').datagrid('getSelected');	// get datagrid object

            var r2 = $('#itemcode2').combogrid('grid').datagrid('getSelected');	// get datagrid object
            var r3 = $('#itemcode3').combogrid('grid').datagrid('getSelected');	// get datagrid object

            if(r!=null){
                if(r2!=null){
                    if(r.itemid==r2.itemid){
                        $('#itemcode1').combogrid('clear');
                        openfwfcz3(1);
                        $.messager.alert('提示', '该收入项目已经添加！', 'info');
                        return;
                    }
                }
                if(r3!=null){
                    if(r.itemid==r3.itemid){
                        $('#itemcode1').combogrid('clear');
                        openfwfcz3(1);
                        $.messager.alert('提示', '该收入项目已经添加！', 'info');
                        return;
                    }
                }

            }

            $('#sl1').show();
            $('#originfund1').show();
            $('#upperlimit1').show();
            $('#btnUnitVsItem1').show();
            if(r!=null){
                $('#itemname1').val(r.itemname);
            }
            $('#sl1').val(1);
            $('#originfund1').val(0.00);
            $("#ishave1").val("true");

        }
    })
    $('#itemcode2').combogrid({
        onChange: function(){
            var r2 = $('#itemcode2').combogrid('grid').datagrid('getSelected');	// get datagrid object

            var r = $('#itemcode1').combogrid('grid').datagrid('getSelected');	// get datagrid object
            var r3 = $('#itemcode3').combogrid('grid').datagrid('getSelected');	// get datagrid object
            if(r2!=null){
                if(r!=null){
                    if(r2.itemid==r.itemid){
                        $('#itemcode2').combogrid('clear');
                        openfwfcz3(2);
                        $.messager.alert('提示', '该收入项目已经添加！', 'info');
                        return;
                    }
                }
                if(r3!=null){
                    if(r2.itemid==r3.itemid){
                        $('#itemcode2').combogrid('clear');
                        openfwfcz3(2);
                        $.messager.alert('提示', '该收入项目已经添加！', 'info');
                        return;
                    }
                }
            }

            $('#sl2').show();
            $('#originfund2').show();
            $('#upperlimit2').show();
            $('#upperlimit2').show();
            $('#btnUnitVsItem2').show();
            if(r2!=null){
                $('#itemname2').val(r2.itemname);
            }
            $('#sl2').val(1);
            $('#originfund2').val(0.00);
            $("#ishave2").val("true");
        }
    })
    $('#itemcode3').combogrid({
        onChange: function(){
            var r3 = $('#itemcode3').combogrid('grid').datagrid('getSelected');	// get datagrid object

            var r = $('#itemcode1').combogrid('grid').datagrid('getSelected');	// get datagrid object
            var r2= $('#itemcode2').combogrid('grid').datagrid('getSelected');	// get datagrid object
            if(r3!=null){
                if(r!=null){
                    if(r3.itemid==r.itemid){
                        $('#itemcode3').combogrid('clear');
                        openfwfcz3(3);
                        $.messager.alert('提示', '该收入项目已经添加！', 'info');
                        return;
                    }
                }
                if(r2!=null){
                    if(r3.itemid==r2.itemid){
                        $('#itemcode3').combogrid('clear');
                        openfwfcz3(3);
                        $.messager.alert('提示', '该收入项目已经添加！', 'info');
                        return;
                    }
                }

            }

            $('#sl3').show();
            $('#originfund3').show();
            $('#upperlimit3').show();
            $('#btnUnitVsItem3').show();
            if(r3!=null){
                $('#itemname3').val(r3.itemname);
            }
            $('#sl3').val(1);
            $('#originfund3').val(0.00);
            $("#ishave3").val("true");
        }
    })

    function queryChargeBillHandData() {
        var state = [{"key":"0","value":"未知错误"},{"key":"1","value":"正常"},{"key":"2","value":"票据已用"},{"key":"3","value":"票据已核销"},{"key":"4","value":"票据不存在"},{"key":"5","value":"对账不成功，账户停用"},{"key":"6","value":"验签未通过"},{"key":"7","value":"该票据已超期"}];
        var billnum = $("#billnum").val();
        var unitid = $("#unitcode").val();
        var cantonid = $("#cantoncode").val();
        if(cantonid=="") {
            $.messager.alert('提示', '请选择行政区划!', 'info');
            $("#cantonid").focus();
            return;
        }
        if(unitid=="") {
            $.messager.alert('提示', '请选择执收单位!', 'info');
            $("#unitid").focus();
            return;
        }
        if(billnum=="") {
            $.messager.alert('提示', '请输入划款单号!', 'info');
            $("#billnum").focus();
            return;
        }
        if(billnum.length!=10) {
            $.messager.alert('提示', '请输入正确的划款单号!', 'info');
            $("#billnum").focus();
            return;
        }
        $.ajax({
            type: "POST",
            url: prefix+'/view/chargebill/queryChargeBillHandData',
            dataType: "json",
            data: { billnum: billnum,cantonid:cantonid,unitid:unitid},
            success: function (dataOne) {

                var data =new DOMParser().parseFromString(dataOne.data, "text/xml")
                var billstate = $(data).find("billstate").text();
                if(billstate!="1") {
                    $("#ischeck").val("0");
                    $('#paybutton').attr('disabled',true);
                    for(var p in state) {
                        if(state[p].key==billstate) {
                            alert(state[p].value);
                        }
                    }
                    return;
                }else{
                    $("#ischeck").val("1");
                    $('#paybutton').attr('disabled',false);

                    $('#payeebank').combogrid({
                        panelMaxHeight: 150,
                        panelWidth:510,
                        idField:'accountcode',
                        textField:'bankname',
                        url: prefix+'/base/basedata/findBankVoView',
                        queryParams: {cantonid:cantonid},
                        columns:[[
                            {field:'accountcode',title:'收款人账号',width:80},
                            {field:'accountname',title:'收款人全称',width:160},
                            {field:'bankname',title:'收款人开户银行',width:260}
                        ]],
                    });

                }
                evaluay();
            }
        })
    }

    $('#payeebank').combogrid({
        onChange: function(){
            var g = $('#payeebank').combogrid('grid');	// get datagrid object
            var r = g.datagrid('getSelected');	// get the selected row
            $('#payee').val(r.accountname);
            $('#payeeaccount').val(r.accountcode);
        }
    })

    function pay(){
        var payer=$("#payer").val();
        var originfund=$("#originfund").val();
        if(payer=="") {
            $.messager.alert('提示', '请输入付款人全称!', 'info');
            return;
        }
        if(originfund==""){
            $.messager.alert('提示', '请输入金额!', 'info');
            return;
        }
        if (originfund < 0 || originfund == 0){
            $.messager.alert('提示', '金额不能为0或负数!', 'info');
            return;
        }

        var reg = /(^[1-9]([0-9]+)?(\.[0-9]{1,2})?$)|(^(0){1}$)|(^[0-9]\.[0-9]([0-9])?$)/;

        for(var i=1;i<=3;i++){
            var ishave = $("#ishave"+i).val();
            if(ishave=="true"){
                var num = $("#originfund"+i).val();
                if (!reg.test(num)) {
                    alert("金额格式不正确");
                    return;
                }
            }
        }
        $('#ChargeBillHandForm').form({
            url: prefix+'/view/chargebill/chargebillhandpayview',
            onSubmit:function(param){
                var t = $('#cantoncode').combotree('tree').tree('getSelected');	// get the tree object
                var r = $('#unitcode').combogrid('grid').datagrid('getSelected');
                var r3 = $('#itemcode3').combogrid('grid').datagrid('getSelected');	// get datagrid object
                var r1 = $('#itemcode1').combogrid('grid').datagrid('getSelected');	// get datagrid object
                var r2= $('#itemcode2').combogrid('grid').datagrid('getSelected');
                var t2 = $('#payeebank').combogrid('grid').datagrid('getSelected');	// get datagrid object
                param.cantonid=t.id;
                param.acode=t.acode;
                param.unitid=r.unitid;
                param.unitcode=r.unitcode;
                param.bankidone=t2.bankid;
                if(r1!=null){
                    param.fromitemid1=r1.itemid;
                }
                if(r2!=null){
                    param.fromitemid2=r2.itemid;
                }
                if(r3!=null){
                    param.fromitemid3=r3.itemid;
                }
                var isValid = $(this).form('validate');
                if (isValid){
                    $.messager.progress({
                        title: '提示',
                        msg: '数据处理中，请稍候……',
                        text: ''
                    });
                }
                return isValid;
            },
            success:function(data) {
                $.messager.progress('close');
                var data = eval('(' + data + ')');
                if (data.success) {
                    location=prefix+'/view/chargebill/chargebillhandview';
                }
                alert(data.msg);
            }
        });
        $('#ChargeBillHandForm').submit();
    }
</script>
</body>
</html>
